import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
         {
           path: "/login",
           component: () => import("@/views/login/index"),
           hidden: true
         },
         {
           path: "/404",
           component: () => import("@/views/error-page/404"),
           hidden: true
         },
         {
           path: "/401",
           component: () => import("@/views/error-page/401"),
           hidden: true
         },

         // 仓储管理
         {
           path: "/",
           component: Layout,
           redirect: "/dashboard",
           meta: {
             title: "仓储管理",
             icon: "dashboard",
             roles: ["admin", "editor"] // you can set roles in root nav
           },
           children: [
             {
               path: "dashboard",
               name: "dashboard",
               component: () => import("@/views/dashboard/table"),
               name: "table",
               meta: { title: "仓库管理", icon: "table" }
             },

             {
               path: "tree",
               component: () => import("../views/dashboard/tree"),
               name: "tree",
               meta: { title: "分区管理", icon: "tree" }
             },

             {
               path: "from",
               component: () => import("../views/dashboard/from"),
               name: "from",
               meta: { title: "货架管理", icon: "form" }
             },
             {
               path: "five",
               component: () => import("../views/dashboard/five"),
               name: "five",
               meta: { title: "库位管理", icon: "new" }
             }
           ]
         },

         // 订单管理
         {
           path: "/pingcart",
           component: Layout,

           alwaysShow: true, // will always show the root menu
           name: "pingcart",
           meta: {
             title: "订单管理",
             icon: "example"
             // roles: ['admin', 'editor'] // you can set roles in root nav
           },
           children: [
             {
               path: "order",
               component: () => import("../views/pingcart/order"),
               name: "order",
               meta: {
                 title: "国内订单",
                 icon: "table"
               }
             },
             {
               path: "pingcart",
               component: () => import("../views/pingcart/orders"),
               name: "Shoppingcart",
               meta: {
                 title: "国际订单",
                 icon: "createtask"
               }
             }
           ]
         },

         // 财务统计
         {
           path: "/caiwu",
           component: Layout,
           name: "Caiwu",
           meta: {
             title: "财务统计",
             icon: "marketing"
           },
           children: [
             {
               path: "financial",
               component: () => import("../views/caiwu/financial"),
               name: "financial",
               meta: { title: "余额明细", icon: "task" }
             },
             {
               path: "finance",
               component: () => import("../views/caiwu/finance"),
               name: "finance",
               meta: { title: "积分明细", icon: "task" }
             },
             {
               path: "recharge",
               component: () => import("../views/caiwu/recharge"),
               name: "recharge",
               meta: { title: "充值管理", icon: "el-icon-s-shop" }
             },
             {
               path: "coupon",
               component: () => import("../views/caiwu/coupon"),
               name: "coupon",
               meta: { title: "优惠券", icon: "new" }
             }
           ]
         },

         // 报价系统
         {
           path: "/quote",
           component: Layout,
           name: "Quote",
           meta: {
             title: "报价系统",
             icon: "nested"
           },
           children: [
             {
               path: "national",
               component: () => import("../views/quote/national"),
               name: "National",
               meta: { title: "国家管理", icon: "table" }
             },
             {
               path: "channel",
               component: () => import("../views/quote/channel"),
               name: "Channel",
               meta: { title: "渠道管理", icon: "table" }
             },
             {
               path: "flat",
               component: () => import("../views/quote/flat"),
               name: "Flat",
               meta: { title: "偏远地区设置", icon: "table" }
             },
             {
               path: "far",
               component: () => import("../views/quote/far"),
               name: "Far",
               meta: { title: "汇率设置", icon: "table" }
             },
             {
               path: "overRules",
               component: () => import("../views/quote/overRules"),
               name: "overRules",
               meta: { title: "超长超重规则", icon: "table" }
             },
             {
               path: "subsection",
               component: () => import("../views/quote/subsection"),
               name: "subsection",
               meta: { title: "大货分段", icon: "table" }
             },
             {
               path: "service",
               component: () => import("../views/quote/service"),
               name: "Service",
               meta: { title: "增值服务设置", icon: "table" }
             },
             {
               path: "shipping",
               component: () => import("../views/quote/shipping"),
               name: "Shipping",
               meta: { title: "出货公司", icon: "table" }
             }
           ]
         },

         // 客户管理
         {
           path: "/crm",
           component: Layout,
           meta: {
             title: "客户管理",
             icon: "new"
             //   roles: ['admin', 'editor']
           },

           children: [
             {
               path: "crm",
               component: () => import("../views/crm/index"),
               name: "index",
               meta: { title: "客户管理", icon: "createtask" }
             },
             {
               path: "crm1",
               component: () => import("../views/crm/tier"),
               name: "Dashboard",
               meta: { title: "会员级别", icon: "createtask" }
             }
           ]
         },

         // 营销数据
         {
           path: "/marketing",
           component: Layout,
           redirect: "",
           alwaysShow: true,
           name: "",
           meta: { title: "营销数据", icon: "password" },
           children: [
             {
               path: "alteration",
               component: () => import("../views/marketing/alteration "),
               name: "",
               meta: { title: "积分变更管理", icon: "task" }
             },
             {
               path: "distribution",
               component: () => import("../views/marketing/distribution"),
               name: "",
               meta: { title: "分销数据", icon: "task" }
             }
           ]
         },

         // 权限管理
         {
           path: "/turnover",
           component: Layout,
           redirect: "",
           alwaysShow: true,
           name: "",
           meta: { title: "权限管理", icon: "password" },
           children: [
             {
               path: "turnover",
               component: () => import("../views/turnover/turn"),
               name: "",
               meta: { title: "人员权限管理", icon: "task" }
             }
           ]
         },

         // 系统自定义
         {
           path: "/permission",
           component: Layout,
           alwaysShow: true,
           name: "",
           meta: { title: "系统自定义", icon: "createtask" },
           children: [
             {
               path: "permission",
               component: () => import("../views/permission/permission"),
               name: "permission",
               meta: { title: "账号管理", icon: "new" }
             },

             //  {
             //    path: "pictures",
             //    component: () => import("../views/permission/pictures"),
             //    name: "pictures",
             //    meta: { title: "小程序内容", icon: "tree" }
             //  },
             {
               path: "evaluate",
               component: () => import("../views/permission/evaluate"),
               name: "evaluate",
               meta: { title: "评价管理", icon: "form" }
             },
             {
               path: "suggestion",
               component: () => import("../views/permission/suggestion"),
               name: "suggestion",
               meta: { title: "建议", icon: "createtask" }
             },
             {
               path: "general",
               component: () => import("../views/permission/general"),
               name: "general",
               meta: { title: "通用文章", icon: "createtask" }
             }
           ]
         },

         // 404 page must be placed at the end !!!
         { path: "*", redirect: "/404", hidden: true }
       ];

// {
//   path: '/error',
//   component: Layout,
//   redirect: 'noRedirect',
//   name: 'ErrorPages',
//   meta: {
//     title: 'Error Pages',
//     icon: '404'
//   },
//   children: [
//     {
//       path: '401',
//       component: () => import('@/views/error-page/401'),
//       name: 'Page401',
//       meta: { title: '401', noCache: true }
//     },
//     {
//       path: '404',
//       component: () => import('@/views/error-page/404'),
//       name: 'Page404',
//       meta: { title: '404', noCache: true }
//     }
//   ]
// },

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
